package cn.yzfy.common.web;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @author 一朝风月
 * @date 2025/9/11 13:54
 * @Code 面向注解面向卿，终无解释再无你
 * @description 接口再度封装模板继承即可调用
 */

public class BaseController {
    /**
     * 获取当前请求
     * @return
     */
    protected HttpServletRequest getRequest() {
        ServletRequestAttributes attributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        assert attributes != null;
        return attributes.getRequest();
    }

    /**
     * 获取当前响应
     * @return
     */
    protected HttpServletResponse getResponse() {
        ServletRequestAttributes attributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        assert attributes != null;
        return attributes.getResponse();
    }
}
